﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_AddMailAttch]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_AddMailAttch];
GO
CREATE PROCEDURE [dbo].[sproc_AddMailAttch]
    @FileName nvarchar(255),
    @FileSize  int=0,
    @FileAttribute int=0,
    @FileVisualPath nvarchar(255) ='',
    @FileAuthor nvarchar(255)='',
    @FileCatlog nvarchar(255)='',
    @Finished bit=1
/*
==============================================

功能:添加邮件的附件
参数:
    @FileName         附件的文件名
    @FileSize          附件大小
    @FileAttribute         附件的文件属性(暂未使用)
    @FileVisualPath     附件的虚拟相对目录
    @FileAuthor        附件的作者(默认为发送者)
    @FileCatlog         附件的分类(默认为邮件)
    @Finished bit=1        是否除去关联标记
==============================================
*/
AS


INSERT INTO UDS_FILES ([DOCID],[FileName],[FileSize],[FileAttribute],[FileVisualPath],[FileAuthor],[FileCatlog],[FileAddedDate])
    SELECT DOCID,@FileName,@FileSize,@FileAttribute,@FileVisualPath,@FileAuthor,@FileCatlog,getdate() 
        FROM UDS_DOCUMENT 
        WHERE DOCATTRIBUTE =1 AND DOCSIGN = @@SPID 
--是否除去关联标志
IF @Finished =1
    UPDATE UDS_DOCUMENT 
        SET DOCATTRIBUTE =0 ,DOCSIGN=0
        WHERE DOCATTRIBUTE =1 AND DOCSIGN = @@SPID